<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<%@page import="com.netscenery.yang.model.Bits"%>
<%@page import="com.netscenery.yang.model.Bit"%>
<%@page import="offer.GetDataSource"%>
<%@page import="offer.SessionObj"%>
<%@page import="com.netscenery.yang.model.Union"%>
<%@page import="com.netscenery.yang.model.BuiltinType"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.netscenery.yang.model.Type"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Union union = new Union();
//获取结点对象
Object itemNode = request.getAttribute("itemNode");
String StatusStr ="";
for(int i = 0 ; i < GetDataSource.getStatusList().length ; i ++){
	StatusStr += GetDataSource.getStatusList()[i] +"_";
}
StatusStr = StatusStr.substring(0, StatusStr.length()-1);
if( null != itemNode){
	union = (Union)itemNode;
}
SessionObj sessionObj = (SessionObj)request.getSession().getAttribute("sessionObj");
String control_disabled = "";
if(!sessionObj.getModuleStatus().toString().equalsIgnoreCase("EDITING")){
 control_disabled ="disabled='disabled'";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Union</title>
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/items.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/subItems.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/index.css" />
    <script type="text/javascript"  src="<%=basePath%>jstree-v.pre1.0/_lib/jquery.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/index.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/union.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/StringUtil.js"></script>
</head>
<body class="body">
 <div id="UnionSubType_tab"  style="display:none;padding:0px;margin:0px;max-height:560px;height:560px;">
 <iframe width="100%" id="UnionType_Iframe" name="MimInfo_Iframe"  height=100% border="0" frameborder="0" src=""  ></iframe>
 </div>
<div id="mainContent" class="" style="padding:0px;margin:0px;">
 <form id="unionForm" method="post" action="<%=basePath %>BitsOpreateServlet" class="IndexFormStyle" >
   <input type="hidden"  id="nodeId" name="nodeId" value="<%=request.getAttribute("nodeId") %>"  />
   <div id="TableContent" class="typeSubContent" >
      <div class="itemTitle">
          The Type [<%=union.getClass().getSimpleName() %>] information 
      </div>
      &nbsp;Type name:&nbsp;<input class="inputText" id="bits_name" name="bits_name" value="<%=union.getName() %>" readonly="readonly" /><br/><br/>
      <input type="hidden" id="bits_para" name="bits_para" value="" /><!-- 用于存放让参数 -->
      <input type="hidden" id="StatusStr" name="StatusStr" value="<%=StatusStr %>" /><!-- 用于存放Status数组-->
      <!-- ************Patterns Length Begin******************************************************************************** -->
      	&nbsp;Union: <!--<input type="button" id="B_unionAdd" name="B_unionAdd" value="add" /> -->
   		<div id="rangeItemContent" style=" padding-top:2px;" >
       	 &nbsp;Add Items &nbsp;Type:&nbsp;
	     <select style="width:150px;   height:23px;" onchange="getUnionDerivedType(this.value)"   class="inputSelect" id="_baseType" name="_baseType">
	          <% ArrayList<String> baseTypeList =  BuiltinType.getBuiltinTypes(); %>
	          	   <option  value="" ></option>  
	          <% for(int i = 0 ; i < baseTypeList.size(); i++ ){ %>
	                <% if(baseTypeList.get(i).equalsIgnoreCase("union")||
	                baseTypeList.get(i).equalsIgnoreCase("empty")||
	                baseTypeList.get(i).equalsIgnoreCase("leafref")){ continue; } %>
	                <option  value="<%= baseTypeList.get(i)%>" ><%=baseTypeList.get(i) %></option>   
	         <%  } %>
	     </select>
	     <span id="_derivedTypeSpan" style="display:none;" >&nbsp;DerivedType:</span>
	     <select id="_derivedType" style="width:150px; height:23px; display:none;" class="inputSelect"  name="_derivedType">
	     </select>
	     &nbsp;<input type="button" id="addUnionItemsButton" value = " add items " onclick ="Show_SubTypeEdit()" />
        </div>
      <div class="inContent">
      	<div id="SubTypeContent" class="itemContent">
	        <%for(int i = 0 ; i < union.getTypesNumber();i++ ){ %>
	        <div class="rangeItem">
	            <span id="typeName_<%=i %>" class="ListSpan" style="width:250px">&nbsp;<%=union.getType(i).getName() %></span>
		     	<a href='#' class='rangeAdd' onclick="editSubType('<%=union.getType(i).getBaseType().getName() %>','<%=(union.getType(i).getDerived()==null?"":union.getType(i).getName()) %>')" ><img class='buttonBcImg' width='25' src='<%=basePath%>images/edit.jpg' /></a>
		     	<a href='#' class='rangeRemove' onclick='deleteSubType(<%=i %>)' ><img class='buttonBcImg' width='25' src='<%=basePath%>images/delete.png' /></a>
	     	</div>
	        <%} %>
        </div>
      </div><!-- inContent end  -->
      <!-- ************Patterns Length Begin******************************************************************************** -->
   </div>
   <div id="submitContent" class="submitContent">
     <input type="button" <%=control_disabled %> onclick="fromSubmit()" value="Apply"  />
   </div>
   </form>
</div>
 <script type="text/javascript">
	 $(document).ready(function(){
	 	}
	 );
	 function fromSubmit(){
	   parent.closeTab('type');
	 }
  function Show_SubTypeEdit(){
 	var baseType    = document.getElementById("_baseType").value;
 	var derivedType = document.getElementById("_derivedType").value;
 	if("" == baseType){
 	    alert("Type:不能为空！");
 	    return false;
 	}
 	openUnionTypeEdit();
 	var url = "<%=basePath%>GoToFindUnionTypeServlet?parent_nodeId="+document.getElementById("nodeId").value+"&baseType="+baseType+"&derivedType="+derivedType+"&opType=add";
 	opensrc("UnionType_Iframe",url);
 } 
 function editSubType(baseType,derivedType){
    //全局变量，标记当前是编辑还是新增
    isEditSubType_Op = true;
 	openUnionTypeEdit();
 	var url = "<%=basePath%>GoToFindUnionTypeServlet?parent_nodeId="+document.getElementById("nodeId").value+"&baseType="+baseType+"&derivedType="+derivedType+"&opType=edit";
 	opensrc("UnionType_Iframe",url);
 }
 </script>

</body>
</html>